<template>
  <base-breadcrumb :title="$route.meta.title">
    <!-- 质量创优奖项台账 -->
    <div id="base-breadcrumb" style="position: relative; overflow: hidden">
      <!-- 搜索 -->
      <searchData :searchData="searchArr" @search="search"></searchData>
      <!-- 表格 -->
      <a-card :bordered="false">
        <!-- <title-name :title="$route.meta.title"></title-name> -->
        <!-- 表格 -->
        <list-table
          ref="table"
          tableLayout="fixed"
          size="default"
          :columns="columns"
          :request="loadData"
          :rowSelection="rowSelection"
          :isShowCountBar="false"
          :selectConfig="{ use: true, type: 'checkbox', rowKey: 'id' }"
          :exportPermission="{ select: [
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_045_aexp_06'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_045_aexp_06'
                      }
              ], all: [
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_045_sexp_05'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_045_sexp_05'
                      }
              ] }"
          :exportConfig="{ use: true, select: '质量创优奖项台账', all: '质量创优奖项台账' }"
        >
          <a-button slot="prefix" v-btnPermission="[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_045_add_01'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_045_add_01'
                      }
              ]" icon="plus" type="primary" @click="handleManage(2)"
            >新增质量创优奖项台账</a-button
          >
          <!-- 统计汇总 -->
          <AuditSummary
            slot="bottom"
            title="质量创优奖项"
            :form="queryParam"
            :loadCount="loadCount"
            :api="api"
            :countList="countList"
          />
          <template slot="actions" slot-scope="text, record">
            <MoreButton>
            <a v-btnPermission="[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_045_loo_04'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_045_loo_04'
                      }
              ]" @click="handleManage(0, record)">查看</a>
            <!-- 公司人员可编辑所有的，分公司人员只能编辑自己分公司的 -->
            <template
              v-if="
                $currentPost().code === 'CO' ||
                ($currentPost().code === 'BC' &&
                  record.submitLevel === $currentPost().code &&
                  $currentPost().id === record.branchComId)
              "
            >
              <a v-btnPermission="[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_045_edi_02'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_045_edi_02'
                      }
              ]" @click="handleManage(1, record)">编辑</a>
              <a v-btnPermission="[
                      {
                        ident: 'prma_seex',
                        code: 'seex_qm_045_del_03'
                      },
                      {
                        ident: 'prma_buco',
                        code: 'buco_qm_045_del_03'
                      }
              ]" @click="handleRemove(record.id)">删除</a>
            </template>
            </MoreButton>
          </template>
          <!-- 联系地址 -->
          <a slot="website" slot-scope="text" :href="text" target="_blank">{{ text }} </a>
        </list-table>
      </a-card>
    </div>
  </base-breadcrumb>
</template>

<script>
import { excellenceTable } from '@/api/quality/quality' // api
import Selector from '@/components/Select/Selector' // 选择器
import BasePage from '@/views/basePage'
import AuditSummary from '@/views/quality/components/AuditSummary' // 统计汇总

const searchArr = [
  // 搜索框
  {
    name: '奖项名称',
    type: Selector,
    selectType: '52',
    valueKey: 'prizeNameId'
  },
  {
    name: '奖项类别',
    type: Selector,
    selectType: '49',
    valueKey: 'prizeTypeId'
  },
  {
    name: '主管单位',
    type: 'input',
    value: 'directorUnit'
  },
  {
    name: '评审状态',
    type: Selector,
    selectType: '51',
    valueKey: 'reviewStatusId'
  }
]
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '奖项名称',
    ellipsis: true,
    dataIndex: 'name'
  },
  {
    title: '奖项类别',
    ellipsis: true,
    dataIndex: 'prizeTypeName'
  },
  {
    title: '主管单位',
    ellipsis: true,
    dataIndex: 'directorUnit'
  },
  {
    title: '评审时间',
    ellipsis: true,
    dataIndex: 'reviewMonth'
  },
  {
    title: '主管单位联系方式',
    ellipsis: true,
    dataIndex: 'phone'
  },
  {
    title: '主管单位网址',
    dataIndex: 'website',
    scopedSlots: { customRender: 'website' }
  },
  {
    title: '创建人',
    // ellipsis: true,
    dataIndex: 'filler'
  },
  {
    title: '评审状态',
    dataIndex: 'reviewStatusName'
  },
  {
    title: '操作',
    dataIndex: 'actions',
    width: '150px',
    align: 'center',
    scopedSlots: { customRender: 'actions' }
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    AuditSummary
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      removeApi: excellenceTable,
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        this.loadCount++
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return excellenceTable.postList(requestParameters).then((res) => {
          return res
        })
      },
      rowSelection: {
        onChange: (e) => {
          console.log(e, '打印选择');
          this.countList[1].value = e.length
        },
      },
      editModel: 0,
      api: excellenceTable, // 汇总api
      loadCount: 0, // 汇总加载控件
      countList: [
        {
          title: '总数：',
          value: 'total'
        },
        {
          key: 'select',
          title: '已选择',
          value: 0
        },
        {
          title: '正常评审',
          value: 'normal'
        },
        {
          title: '暂停评审',
          value: 'stop'
        },
        {
          title: '停止评审',
          value: 'cease'
        }
      ], // 汇总列表
      form: {},
      exportLoading: {
        0: false,
        1: false
      } // 导出loading
    }
  },
  methods: {
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record) {
      this.editModel = type
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: 'excellenceTableEdit',
        query
      })
    }
  }
}
</script>
